package com.example.ormsqlsplicingframe1.aop;


import com.example.ormsqlsplicingframe1.note.JoinSession;
import com.example.ormsqlsplicingframe1.session.SessionUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Order(9998)
@Component
public class JoinSessionAop {

    /**
     * 配置切入点
     */
    @Pointcut("@annotation(com.example.ormsqlsplicingframe1.note.JoinSession)"+ "|| @within(com.example.ormsqlsplicingframe1.note.JoinSession)")
    public void apoPointCut() {
        // 无方法体，主要在@Pointct中体现@AopTest注解类所在位置
    }


    @Around("apoPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        MethodSignature method = (MethodSignature) joinPoint.getSignature();


        JoinSession session = method.getMethod().getAnnotation(JoinSession.class);
        if (session != null){
            SessionUtil.getSession().toggleData(session.value());
        }

        return joinPoint.proceed();

    }

}
